package com.qiye.livevideo.utils;

import java.text.ParseException;
import java.text.SimpleDateFormat;
import java.util.Date;

/**
 * Created on 2019/4/19.
 *
 * @author meishijun
 */
public class DateUtils {
    private static String formatMonth = "yyyy-MM";
    private static String dateFormat1 = "yyyy-MM-dd HH:mm:ss";
    private static String dateFormat = "yyyy-MM-dd";

    public DateUtils() {
    }

    public static String formatDate(Date date) {
        SimpleDateFormat simpleDateFormat = new SimpleDateFormat(dateFormat);
        return date == null ? "" : simpleDateFormat.format(date);
    }

    public static String formatDateTime(Date date) {
        SimpleDateFormat simpleDateFormat = new SimpleDateFormat(dateFormat1);
        return date == null ? "" : simpleDateFormat.format(date);
    }

    public static String formatMonth(Date date) {
        SimpleDateFormat format = new SimpleDateFormat(formatMonth);
        return format.format(date);
    }

    public static String formatDateByPattern(Date date, String pattern) {
        SimpleDateFormat dfs = new SimpleDateFormat(pattern);
        return dfs.format(date);
    }
    public static Date formatDateByString(String dataStr) throws ParseException {
        SimpleDateFormat simpleDateFormat = new SimpleDateFormat(dateFormat1);
        return simpleDateFormat.parse(dataStr);
    }
}

